1. Introduction
    
    LibCAN is Controller library.
    App can use it to config & control CAN Controller and communicate with CAN devices on the CAN bus.

2. About LibCAN

    2.1 Resource Handles
        Before using any LibCAN Functions, App should create a resource handle.
            App can declare a static handle - hLibCAN, then use LibCAN_Initialize to initialize it.
        
        After creating a handle resource, App can open(or attach to) a CAN Controller.
        This library provides two methods to open a CAN Controller.
            One is for PCI based Controller, another is for non-PnP based Controller.
            LibCAN_Open0 is PCI based method, and it need PCI BusNumber, DeviceNumber, FunctionNumber.
            LibCAN_Open1 is non-PnP based method, and it need BaseSpace, BaseAddress.
            In general, Legacy devices are non-PnP based and are on LPC bus.
        
        App call LibCAN_Close to close(detach) a CAN Controller.

    2.2 CAN Configuration
        Fisrt step, App should configure CAN clock through LibCAN_InitClock.
            In general, CAN clock source is external source. so bExternalClock is set to 1.
            ClockHz can be 50MHz or 20MHz depended on board specification.
            
        Second step, App should configure CAN Bus Timing through LibCAN_InitBusTiming & LibCAN_InitBaudRate
            CAN Bus Timing is composed of SYNC, PropSEG, PhaseSEG1, and PhaseSEG2.
            According to CAN spec., total time of one bit can be form 8 to 25 Tq.
            The following table list possible combination of CAN Bus Timing.
            // SYNC + Prop + Seg1 + Seg2
            // 1    + 4    + 1    + 2 = 8
            // 1    + 3    + 2    + 2 = 8   
            // 1    + X    + 3    + 3 = 8~15 => default setting
            // 1    + X    + 4    + 4 = 10~17
            // 1    + X    + 5    + 5 = 12~19
            // 1    + X    + 6    + 6 = 14~21
            // 1    + X    + 7    + 7 = 16~23
            // 1    + X    + 8    + 8 = 18~25
            // 1    + 8    + 8    + 8 = 25
            
            Note: The possible total Tq can be derive from Source clock.
                for example, Source clock 50MHz can be divide 10Tq or 25Tq with no remainder.
            
            BaudRate range is 1000k < 500k, 250k...1k... < 500.
             
             
        Third step, App should configure Bus Off Handle through LibCAN_BusOffHandle.
            If Bus Off occurs, CAN hardware will automatically stop. Then Software(Driver) should restart it.
            BusOffHandleMethod ID:
            // 0 : the driver dont handle BusOff. App will handle this situation.
            // 1 : the driver handle BusOff according to the typic method - restart after 128 bit cycle.
            // 2 : the driver handle BusOff according to the speedup method - return to Error Active State
            // 3 : the driver handle BusOff according to the speedup method - return to Error Passive State
        
        Fourth step, App should configure Global Control through LibCAN_SetGlobalControl
            CANGlobalControl.TransmitPriorityMode
                0: buffer index, index 0 is first priority.
                1: ID, the low value of ID has high priority.
                2: round robin index, the order of sending Tx buffer is 0, 1, 2, 0, 1, 2....
                This hardware has three Tx buffer, and each time hardware can only send a tx buffer,
                so app can program the priority of tx buffer through specfying TransmitPriorityMode.
                
            CANGlobalControl.bArbitrationLostRetry, enable ArbitrationLostRetry
                If there is a Arbitration Lost when transmitting Tx reqeust, CAN hardware will re-try until aborting request.
                
            CANGlobalControl.bBusErrorRetry, enable BusErrorRetry
                If there is a Bus Error when transmitting Tx reqeust, CAN hardware will re-try until aborting request.
                00jfriyxaudo
            CANGlobalControl.bPowerSaving, enable Power saving
        00jfriyxaudo
    2.3 CAN Message
        After CAN Configuration, App can start(active) the CAN Controller through LibCAN_Start.
            LibCAN_Start, to active CAN.
            LibCAN_Stop, to stop CAN.
            LibCAN_ClearRxFIFO, to clear Rx FIFO of the CAN Driver.
            LibCAN_GetGlobalStatus, to return the current status of CAN hardware.
        
        Now, App can send CAN Message to the bus.
            Synchronously send CAN message - LibCAN_SendMessage
                Driver handle this IO request until the request be done or aborted.
                If this IO request is done, the Transmit Status show it's transmitting result.
                    TransmissionComplete = 1, This transmission is complete and no error.
                    TransmissionComplete = 0, This transmission is not complete and has errors.
                        RequestAborted = 1, if timeout, driver will abort this request. 
                        ArbitrationLost = 1, ArbitrationLost occurs when transmitting this reques and there is no ArbitrationLostRetry
                        BusError = 1, BusError occurs when transmitting this request and there is no BusError
                        BusOff = 1, BusOff occurs when transmitting this request.
                
        All CAN transmitting functions will return a Transimt Status.
            bActionDone = 1 indicate the request of sending Tx message is done.
            bActionDone = 0 indicate the request of sending Tx message is not done.

            bTransmissionComplete = 1 indicate the sending message is complete(finished)
                
            bTransmissionComplete = 0 indicate the sending message is incomplete(failed)
                and the failed reason(TransmitError) is one of the RequestAborted, ArbitrationLost, BusError, BusOff.
            
            
            
        App can monitor(query)Rx FIFO through LibCAN_GetRxFIFOStatus and LibCAN_GetRxMessage.
            There is a queue to keep all Rx CAN message on CAN Controller Driver.
                The queue size is 64.
            If a overrun occurs, the last Rx CAN message will be dropped.
        
        
    2.5 

3. Using LibCAN
    
    LoopbackMaster
    LoopbackSlave
    
4. References
    
    LibCAN functions
    LibCAN structures
